Skip to content

feat(mcp): run saved project scripts - #8714

Open
juliusmarminge wants to merge 4 commits into
agents/mcp-terminals/controlsfrom
agents/mcp-terminals/scripts
Open

juliusmarminge wants to merge 4 commits into
agents/mcp-terminals/controlsfrom
agents/mcp-terminals/scripts

Conversation

@juliusmarminge

@juliusmarminge juliusmarminge commented Aug 30, 2026 •

Copy link
Copy Markdown
Member

Problem

Agents can manage project script definitions through the project MCP surface, but they cannot discover or run a saved script through the managed terminal lifecycle.

Change

Add bounded saved-script discovery, run a saved script ID in a caller-named fresh terminal, and stop only the matching managed run. Ownership is bound to the terminal incarnation and is released by terminal lifecycle events.

Behavior

Script cwd and runtime environment come from the target thread and project. Run and stop reuse #8707's serialized full-access/default authorization boundary. Callers cannot supply command text, host paths, environment variables, or preview actions. A removed or renamed script definition does not prevent stopping its existing run; close, restart, exit, and terminal-ID reuse invalidate the old run handle. Opening plus ownership registration is interruption-safe, while the operation remains honestly non-idempotent. A queued exit preserved across clear releases ownership before the terminal ID is reused.

Focused validation

  • deterministic real Manager/fake-PTY proof that exit queued before clear reaches exited state, invalidates script ownership, and permits safe terminal-ID reuse
  • 62 focused Manager, terminal MCP, and saved-script tests for the latest cross-layer fix
  • original production registration, contract, policy, cwd/environment, partial-failure, and lifecycle validation remains in this layer

Dependency

Upper layer of native stack #8715. Depends on #8707 for scoped terminal resolution, strict fresh creation, terminal-incarnation handles, bounded output, event-drain serialization, and lifecycle controls; the stack is rooted on immutable rollout base agents/mcp-controls/base-490318a.

Implemented by GPT-5.6-Sol via Codex in T3 Code.

Note

Add MCP tools to list, run, and stop saved project scripts

  • Adds ProjectScriptMcpService and a three-tool MCP toolkit (t3_project_script_list, t3_project_script_run, t3_project_script_stop) registered on the MCP HTTP server and advertised in orchestration capabilities via savedProjectScripts.
  • Listing returns paginated, bounded command previews with length and truncation metadata. Running opens a fresh owned terminal, writes the saved command, and returns either accepted-input or opened-but-input-failed outcomes. Stopping requires matching project, script, terminal, and incarnation ownership before closing.
  • Extends TerminalManager with admitRunningSessionHandle (atomic ownership under the thread lock) and subscribeSessionInvalidation (notifies on close, restart, replacement, or exit) so the service drops stale ownership.
  • Adds contract schemas in projectScriptMcp.ts with bounded inputs, validated result/failure types, and barrel exports.
  • Adds t3_project_script_list to the Claude read-only MCP allowlist in ClaudeAdapterV2.ts; run and stop are excluded because they mutate.
  • Risk: TerminalManager interface gains two required operations (admitRunningSessionHandle, subscribeSessionInvalidation); out-of-tree implementations of this interface must add both methods.

Macroscope summarized 7c7bdd6.


Note

Medium Risk
Run/stop execute saved commands in real PTYs under the same host-execution boundary as terminal MCP, and TerminalManager’s public interface gains two required methods that mocks must implement.

Overview
Agents can discover and execute project scripts through MCP without supplying arbitrary shell input. The PR adds t3_project_script_list, t3_project_script_run, and t3_project_script_stop, wired through a new ProjectScriptMcpService and registered on the HTTP MCP server alongside existing toolkits.

Listing returns paginated script metadata with bounded command previews. Run opens a fresh owned terminal (caller-chosen terminalId), writes the saved command plus Enter, and records script/run ownership tied to the terminal incarnation. Stop closes only when project, script id, terminal id, and handle still match; ownership is dropped on close, restart, exit, or session invalidation. Run/stop inherit the same full-access / default interaction policy as other terminal mutations; list is read-only.

TerminalManager gains admitRunningSessionHandle (atomic ownership registration under the thread lock) and subscribeSessionInvalidation (notify when an incarnation is replaced). Orchestrator capabilities advertise savedProjectScripts; Claude’s read-only MCP allowlist adds t3_project_script_list only. Contracts, UI tool labels, and user docs are updated accordingly.

Reviewed by Cursor Bugbot for commit 7c7bdd6. Bugbot is set up for automated code reviews on this repo. Configure here.

@juliusmarminge
juliusmarminge marked this pull request as ready for review August 30, 2026 00:53
@coderabbitai

coderabbitai Bot commented Aug 30, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 006f03bc-55f5-46bc-aa69-e5fe613e864f

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Warning

Your free Security trial is over. An organization admin can activate Security or dismiss this notice.


Comment @coderabbitai help to get the list of available commands.

@github-actions github-actions Bot added vouch:trusted PR author is trusted by repo permissions or the VOUCHED list. size:L 100-499 changed lines (additions + deletions). labels Aug 30, 2026
Comment thread packages/contracts/src/projectScriptMcp.ts Outdated
Comment thread apps/server/src/mcp/ProjectScriptMcpService.ts Outdated
@github-actions

github-actions Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Thread transfer impact

⚠️ The latest CI run did not produce a thread transfer result for 7c7bdd6.

This comment will update automatically after the next completed run.

@macroscopeapp

macroscopeapp Bot commented Aug 30, 2026 •

Copy link
Copy Markdown
Contributor

Approvability

Verdict: Not approved

Macroscope's review found this PR not approvable — This PR introduces a production MCP workflow for running and stopping saved project scripts, including new terminal ownership and lifecycle handling across shared server infrastructure. Its user-facing execution capability and cross-component runtime impact warrant human review.

Notes:

  • Diff unchanged. Approvability was decided on eligibility alone.

You can add or adjust custom eligibility rules. Learn more.

@juliusmarminge
juliusmarminge force-pushed the agents/mcp-terminals/scripts branch from 676c470 to 89da9ca Compare August 30, 2026 01:01
Comment thread apps/server/src/mcp/ProjectScriptMcpService.ts Outdated
Comment thread apps/server/src/mcp/ProjectScriptMcpService.ts Outdated

@macroscopeapp macroscopeapp Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Effect service conventions review of the new ProjectScriptMcpService and its contracts/toolkit modules. One convention violation found; everything else (Context.Service tag with inline interface, make/layer ordering and naming, environment-based dependency acquisition, namespace subpath imports, test seams) matches the conventions.

Posted via Macroscope — Effect Service Conventions

Comment thread apps/server/src/mcp/ProjectScriptMcpService.ts Outdated

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes using high effort and found 1 potential issue.

Fix All in Cursor

Bugbot Autofix is ON, but a cloud agent failed to start.

Reviewed by Cursor Bugbot for commit 89da9ca. Configure here.

Comment thread apps/server/src/mcp/ProjectScriptMcpService.ts Outdated
@juliusmarminge
juliusmarminge force-pushed the agents/mcp-terminals/scripts branch 2 times, most recently from 4b79eaf to cb92687 Compare August 30, 2026 01:33
@github-actions github-actions Bot added size:XL 500-999 changed lines (additions + deletions). and removed size:L 100-499 changed lines (additions + deletions). labels Aug 30, 2026
Comment thread apps/server/src/terminal/Manager.ts Outdated
@juliusmarminge
juliusmarminge force-pushed the agents/mcp-terminals/scripts branch from cb92687 to 7848715 Compare August 30, 2026 01:41
Comment thread apps/server/src/terminal/Manager.ts
@juliusmarminge
juliusmarminge force-pushed the agents/mcp-terminals/scripts branch 3 times, most recently from 932dc15 to 4745541 Compare August 30, 2026 02:43
@juliusmarminge
juliusmarminge force-pushed the agents/mcp-terminals/scripts branch from 0b9dd14 to faa8511 Compare August 30, 2026 17:15
Comment thread apps/server/src/terminal/Manager.ts
@juliusmarminge
juliusmarminge force-pushed the agents/mcp-terminals/scripts branch from faa8511 to fe470f7 Compare August 30, 2026 17:30
@juliusmarminge
juliusmarminge force-pushed the agents/mcp-terminals/scripts branch from fe470f7 to a2ab88a Compare August 30, 2026 20:13
@juliusmarminge
juliusmarminge force-pushed the agents/mcp-terminals/scripts branch 2 times, most recently from f3130c1 to 30d351d Compare September 5, 2026 06:06
@juliusmarminge
juliusmarminge force-pushed the agents/mcp-terminals/scripts branch from 30d351d to 7c7bdd6 Compare September 5, 2026 06:21
@juliusmarminge juliusmarminge added the macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews label Sep 30, 2026 — with ChatGPT Codex Connector

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

macroscope-review Opt PRs made by unvouched contributors in for Macroscope review. Vouched contributors auto-reviews size:XL 500-999 changed lines (additions + deletions). vouch:trusted PR author is trusted by repo permissions or the VOUCHED list.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant